package org.weasel.views;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
import org.weasel.business.Iteration;
import org.weasel.controllers.IterationViewController;

public class IterationDetail extends ViewPart {

	public static final String ID = "org.weasel.views.IterationDetail"; // TODO Needs to be whatever is mentioned in plugin.xml

	private Composite top = null;

	private Label lbl_name = null;

	private Text text = null;

	private Label label = null;

	private Text textArea = null;
	
	private IterationChartComposite chartComposite;
	
	
	private IterationViewController controller;

	private Label lblStartDate;

	private Label lblEndDate;

	private Text txtStartDate;

	private Text txtEndDate;

	@Override
	public void createPartControl(Composite parent) {
		// TODO Auto-generated method stub
		top = new Composite(parent, SWT.NONE);
		top.setLayout(null);
		top.addDisposeListener(new org.eclipse.swt.events.DisposeListener() {
			public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) {
				controller.doViewClosedActions();
			}
		});
		lbl_name = new Label(top, SWT.LEFT);
		lbl_name.setText("Name:");
		lbl_name.setBounds(new Rectangle(15, 15, 36, 16));
		text = new Text(top, SWT.BORDER);
		text.setBounds(new Rectangle(60, 15, 286, 19));
		text.addFocusListener(new org.eclipse.swt.events.FocusAdapter() {
			public void focusLost(org.eclipse.swt.events.FocusEvent e) {
				controller.setIterationName(text.getText());
			}
		});
		lblStartDate = new Label(top, SWT.LEFT);
		lblStartDate.setBounds(new Rectangle(360, 16, 61, 18));
		lblStartDate.setText("Start-date:");
		lblEndDate = new Label(top, SWT.LEFT);
		lblEndDate.setBounds(new Rectangle(541, 16, 55, 16));
		lblEndDate.setText("End-date:");
		txtStartDate = new Text(top, SWT.BORDER);
		txtStartDate.setBounds(new Rectangle(426, 15, 100, 19));
		txtStartDate.setEditable(false);
		txtEndDate = new Text(top, SWT.BORDER);
		txtEndDate.setBounds(new Rectangle(607, 15, 100, 19));
		txtEndDate.setEditable(false);
		label = new Label(top, SWT.NONE);
		label.setBounds(new Rectangle(15, 45, 33, 13));
		label.setText("Notes:");
		textArea = new Text(top, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL | SWT.BORDER);
		textArea.setBounds(new Rectangle(60, 45, 646, 166));
		textArea.addFocusListener(new org.eclipse.swt.events.FocusAdapter() {
			public void focusLost(org.eclipse.swt.events.FocusEvent e) {
				controller.setNotes(textArea.getText());
			}
		});
		
		controller = IterationViewController.instance();
		chartComposite = controller.createIterationChartComposite(top, SWT.NONE);
		chartComposite.setBounds(new Rectangle(65,250, 500, 320));
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

	public void showIterationInformation(Iteration iteration) {
		this.setPartName(iteration.getName());
		text.setText(iteration.getName());
		textArea.setText(iteration.getNotes());
		if(iteration.getStartDate()!=null)
			txtStartDate.setText(iteration.getStartDate());
		if(iteration.getEndDate()!=null)
			txtEndDate.setText(iteration.getEndDate());
	}

}  //  @jve:decl-index=0:visual-constraint="10,10,726,371"
